<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
<script src="jquery.min.js"></script>
</head>

<body>

		<form id="uploadImage" enctype="multipart/form-data" action="http://192.168.1.120:8080/bdmall/api/uploadPic.do">
			请选择需要上传的图片：<input type="file" name="file" id="file" accept="image/png,image/gif,image/jpeg,image/bmp"/><br/>
			<button type="submit">上传</button>
		</form>
</body>
<script>

		//上传图片
		$("#uploadImage").submit(function() {
			uploadImage($(this),callback);
			return false;
		});				
		function uploadImage($form) {
				var $fileInput = $form.find("input[name=file]");
				//获取文件
				var myfile = $fileInput[0].files[0];				
				var fr = new FileReader;
				fr.onload = function() {															
					var urls = $form.attr("action");
					var prefix = urls.substring(0, urls.indexOf("/api/")) + "/";
					//获取表单内容
					var dataform = new FormData($form[0]);								
					//设置上传图片
					dataform.append("image", myfile);
					$.ajax({
						type: "post",
						url: urls,
						data: dataform,
						async: false,
						processData: false,
						contentType: false,
						cache: false,
						success: function(result) {
							console.log(result);
						}
					});
				};
				fr.readAsArrayBuffer(myfile);
				return false;
         }
</script>

</html>